package ynu.edu.dao;


import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import ynu.edu.po.Course;

public interface CourseRepository extends CrudRepository<Course, Long> {

    // 自定义查询1：通过课程名称查找课程
    @Query("SELECT c FROM Course c WHERE c.couName = :couName")
    Course findByCouName(@Param("couName") String couName);

    // 自定义查询2：通过学分范围查找课程
    @Query("SELECT c FROM Course c WHERE c.couCredit BETWEEN :minCredit AND :maxCredit")
    Iterable<Course> findByCreditRange(@Param("minCredit") Double minCredit, @Param("maxCredit") Double maxCredit);

    // 自定义修改：更新课程类型
    @Transactional
    @Modifying
    @Query("UPDATE Course c SET c.couType = :couType WHERE c.couId = :couId")
    int updateCourseType(@Param("couId") Long couId, @Param("couType") String couType);
}